/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bea.logic;

import java.util.Random;

/**
 *
 * @author Septu Jamasoka
 */
public class BananaKey {

    public static byte[] kunci;

    public void inputKey(byte[] input) {
        Random r = new Random();
        if (input.length < 8) {
            kunci = new byte[8];
            System.arraycopy(input, 0, kunci, 0, input.length);
            for (int i = 0; i < 8 - input.length; i++) {
                r.setSeed((long) kunci[i]);
                kunci[input.length + i] = (byte) (r.nextInt(124));
            }
        } else {
            kunci = input;
        }
    }

    public byte[] genKeyFeistel(int i) {

        byte[] b = new byte[4];

        i = i % 8;
        b[0] = kunci[i];
        b[1] = (byte) (b[0] + (52));
        b[2] = (byte) (b[1] + (80));
        b[3] = (byte) (b[2] + (17));

        return b;
    }
}
